home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!chi-il4-12
- From: stefmit@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Simple question about constructors
- Date: 3 Mar 1996 05:24:09 GMT
- Organization: Netcom
- Message-ID: <4hbadp$t0p@cloner4.netcom.com>
- References: <4ha7d2$quc@cloner4.netcom.com>
- NNTP-Posting-Host: chi-il4-12.ix.netcom.com
- X-NETCOM-Date: Sat Mar 02 9:24:11 PM PST 1996
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- It seems that the "copy constructor" day is one of my worst in the C++
- learning process. Now I ran into another problem:
- I have a linked list based on a template <class My_type>, which has a node
- class with (obviously) a pointer (let's call it *next) and an element field of
- the type My_type (called data). Then, I have a list class using the node
- above, with its own pointer *head (I am trying to build a sort of stack). I
- was able to build the stack (this was pretty easy), but then I tried to define
- a copy constructor in the list, using something similar to:
- template <class My_type>
- List<My_type> :: List(const List &newList)
- { head -> data = newList.head -> data;
- head -> next = newList.head -> next; }
- I am almost positive that the second line crashes my program when I try to
- intialize an object list based on an existing one (as I copy pointers, instead
- of what they point to - i.e. next), but I have no clue on how to address the
- problem. The example I have in my book deals with strings, thus the
- availability of strcpy or strup functions, that handle the copy. Would anybody
- care to enlighten me on this?
- TIA.
-